#coding:utf-8

from requests import *
import re,MySQLdb
import sys
reload(sys)
sys.setdefaultencoding('utf-8')

headers = { "accept":"text/html,application/xhtml+xml,application/xml;",
            "accept-encoding":"gzip",
            "accept-language":"zh-cn,zh;q=0.8",
            "referer":"Mozilla/5.0(compatible;Baiduspider/2.0;+http://www.baidu.com/search/spider.html)",
            "connection":"keep-alive",
            "user-agent":"mozilla/5.0(windows NT 6.1;wow64) applewebkit/537.36 (khtml,like gecko)chrome/42.0.2311.90 safari/537.36"
            }

for i in range(1,11):
	print str(i)+'=====page'
	url = 'http://www.xicidaili.com'
	url = url + '/wn/'# 国内https代理
	url = url + str(i)
	html = get(url,timeout=5,headers=headers)
	html.encoding = html.apparent_encoding
	proxyip = r'(<td>.*</td>)'
	iplist = re.findall(proxyip,html.text)
	i = 1
	#print iplist#[u'<td>114.101.36.123</td>', u'<td>42421</td>', u'<td>HTTPS</td>', u'<td>1\u5c0f\u65f6</td>', u'<td>18-01-11 10:46</td>'
	for ip in iplist:
		#print ip
		#iip = (ip.split('<td>')[1]).split('</td>')[0]
		iip = re.findall(r'<td>(.*)</td>',ip)
		print iip[0]
		new_url = open("1.txt", "ab+")
		new_url.write(iip[0]+'=')
		if i % 5 == 0:
			new_url.write('\n')
			new_url.close()
		i = i + 1